define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {

    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'reguser/index',
                    add_url: '',
                    edit_url: '',
                    del_url: '',
                    multi_url: 'reguser/multi',
                    table: 'sms_code',
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'id',
                columns: [
                    [
                        {checkbox: true},
                        {field: 'id', title: __('Id'),operate:false},
                        {field: 'phone', title: __('Mobile')},
                        //{field: 'is_voice', title: __('Is_voice')},
                        //{field: 'voice_num', title: __('Voice_num')},
                        //{field: 'voice_time', title: __('Voice_time'), formatter: Table.api.formatter.datetime},
                        {field: 'num', title: __('Send_num'),operate:false},
                        //{field: 'code', title: __('Code')},
                        {field: 'createTime', title: __('Add_time'), formatter: Table.api.formatter.datetime,operate: 'BETWEEN', type: 'datetime', addclass: 'datetimepicker', data: 'data-date-format="YYYY-MM-DD HH:mm:ss"'},
                        //{field: 'ip', title: __('Ip')},
                        //{field: 'is_last', title: __('Is_last')},
                        //{field: 'is_type', title: __('Is_type')},
                        //{field: 'req_url', title: __('Req_url'), formatter: Table.api.formatter.url},
                        {field: 'device', title: __('AppShop')},
                        {field: 'promotion', title: __('Promotion')},
                        {field: 'fromUrl', title: __('FromUrl')},
                        //{field: 'fromUrl', title: __('FromUrl'), formatter: Table.api.formatter.url},
                        {field: 'status', title: __('Status'),searchList: {"0": "注册失败", "1": "注册成功"}, events: Controller.api.events.status, formatter: Controller.api.formatter.status},
                        //{field: 'operate', title: __('Operate'), events: Table.api.events.operate, formatter: Table.api.formatter.operate}
                    ]
                ],
             search: false,
                 //启用普通表单搜索
                 commonSearch: true,
                //可以控制是否默认显示搜索单表,false则隐藏,默认为false
                searchFormVisible: false
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        add: function () {
            Controller.api.bindevent();
        },
        edit: function () {
            Controller.api.bindevent();
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            },

            formatter: {
                status: function (value, row, index) {
                    if(value==0){
                        return "<span style='color: red'>注册失败</span>";
                    }else{
                        return '注册成功';
                    }
                    //return '<div class="input-group input-group-sm" style="width:250px;"><input type="text" class="form-control input-sm" value="' + value + '"><span class="input-group-btn input-group-sm"><a href="' + value + '" target="_blank" class="btn btn-default btn-sm"><i class="fa fa-link"></i></a></span></div>';
                },
            },
            events: {//绑定事件的方法
                status: {
                    //格式为：方法名+空格+DOM元素
                    'click .btn-ip': function (e, value, row, index) {
                        //e.stopPropagation();
                        //console.log();
                        //var container = $("#table").data("bootstrap.table").$container;
                        //var options = $("#table").bootstrapTable('getOptions');
                        ////这里我们手动将数据填充到表单然后提交
                        //$("form.form-commonsearch [name='status']", container).val(value);
                        //$("form.form-commonsearch", container).trigger('submit');
                        //Toastr.info("执行了自定义搜索操作");
                    }
                },

            }
        }
    };
    return Controller;
});